package com.tarry.shop.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiResponses;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel(description = "通用返回")
public class ResultEntity<T> {

    private static final String SUCCESS = "200";
    private static final String ERROR = "500";

    @ApiModelProperty(value = "返回码")
    private String code;
    @ApiModelProperty(value = "返回消息")
    private String msg;
    @ApiModelProperty(value = "返回结果数据")
    private T data;

    public static <T> ResultEntity<T> success(){
        return new ResultEntity(SUCCESS,null,null);
    }

    public static <T> ResultEntity<T> success(T data){
        return new ResultEntity(SUCCESS,null,data);
    }

    public static <T> ResultEntity<T> error(){
        return new ResultEntity(ERROR,null,null);
    }

    public static <T> ResultEntity<T> error(String msg){
        return new ResultEntity(ERROR,msg,null);
    }

    public static <T> ResultEntity<T> error(String msg,T data){
        return new ResultEntity(ERROR,msg,data);
    }

}
